﻿$(document).ready(function (){
	sessionUrl();
	showsession();
	
	
	checkmsg();
	//showOrHideFootBar();
	checklinks();
	showtime = getNowFormatDate();
	startnum = $('.startnum').text();
	showmessages(startnum,showtime);
	//点击加载更多
	$('.showmoremessage').click(function(){
		startnum = $('.startnum').text();
		showmessages(startnum,showtime);
	});
	$(document).on("click",".sMessageDiv",function(){
		var msgid = $(this).attr('msgid');
		var linkk = $(this).attr('link');
		readonemsg(msgid);
		window.location.href = linkk;
	});
});

function showmessages(startnum,showtime){
	$.ajax({
		type:'post',
		url:'../actions/messageAction.php',
		data:	{
					act			:'getmsglist',
					startnum	:startnum,
					showtime	:showtime
				}, 
		async: true,	
		beforeSend:function(){
			showMistAndWait();
		},
		success:function(data){
			//console.log(data);
			if(data){
				$('.allMessages').append(data);
			}else{
				alert('没有更多信息啦');
			}
			hideMistAndWait();
		}
	});
	//hideMistAndWait();
	$('.startnum').text(Number(startnum) + 8);
}

function readonemsg(msgid){
	$.ajax({
		type:'post',
		url:'../actions/messageAction.php',
		data:	{
					act		:'readonemsg',
					msgid	:msgid
				}, 
		async: true,	
		beforeSend:function(){
			showMistAndWait();
		},
		success:function(data){
			console.log(data);
			hideMistAndWait();
		}
	});
	
}